package com.liyawen.web;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.liyawen.entity.Message;

public class SendServlet extends HttpServlet
{
	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		ServletContext application = getServletContext();
		HttpSession session = request.getSession();
		String name = (String) session.getAttribute("name");
		String msg = request.getParameter("msg");
		String date = new SimpleDateFormat("HH:mm").format(new Date());
		
		Message m = new Message();
		m.setName(name);
		m.setMsg(msg);
		m.setDate(date);
		
		List<Message> msgList = (List<Message>) application.getAttribute("msgList");
		if(msgList == null)
		{
			msgList = new ArrayList<Message>();
		}
		
		msgList.add(m);
		application.setAttribute("msgList", msgList);
		
		response.sendRedirect("tojsp.jspx?_m=send");
	
	
	}

}
